package com.base.cn.platform.os.controller.user.binding;

import com.base.cn.platform.os.controller.cmmon.ApiBaseController;
import com.base.cn.platform.os.service.manage.user.binding.UserMobileOrEmailBindingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Map;

/**
 * 用户绑定手机号和邮箱号
 *
 * @author s.li
 * @create 2018-08-30-11:31
 */
@RestController
@RequestMapping("/api/user")
public class ApiUserMobileOrEmailBindingController extends ApiBaseController {

    @Autowired
    private UserMobileOrEmailBindingService userMobileOrEmailBindingService;

    /**
     * 验证原绑定的手机号(如果没有绑定过的手机号，将用不到该接口)
     * @param mobile 手机号
     * @param mobileCode 手机验证码
     * @return Map<String,Object>
     */
    @RequestMapping("/verificationOldMobile")
    @ResponseBody
    public Map<String,Object> verificationOldMobile(@RequestParam("mobile") String mobile,
                                                    @RequestParam("mobileCode") String mobileCode){
        return userMobileOrEmailBindingService.verificationOldMobile(mobile,mobileCode);
    }

    /**
     * 绑定/修改绑定新手机号接口
     * @param userId 用户ID
     * @param mobile 新的手机号
     * @param code 新手机号的验证码
     * @param oldCode 原手机号验证（如果没有绑定过手机号可不传）
     * @return
     */
    @RequestMapping("/updateUserMobile")
    public Map<String,Object> updateUserMobile(@RequestParam("userId") BigDecimal userId,
                                               @RequestParam("mobile") String mobile,
                                               @RequestParam("code") String code,
                                               @RequestParam(value = "oldCode",required = false) String oldCode){
        return userMobileOrEmailBindingService.bindingUserMobile(userId,mobile,code,oldCode);
    }

    /**
     * 验证原绑定的邮箱号(如果没有绑定过的邮箱号，将用不到该接口)
     * @param email 邮箱号
     * @param emailCode 邮箱验证码
     * @return Map<String,Object>
     */
    @RequestMapping("/verificationOldEmail")
    public Map<String,Object> verificationOldEmail(@RequestParam("email") String email,
                                                   @RequestParam("emailCode") String emailCode){
        return userMobileOrEmailBindingService.verificationOldEmail(email,emailCode);
    }

    /**
     * 绑定邮箱号
     * @param userId 用户ID
     * @param email 新的邮箱号
     * @param code 新邮箱号的验证码
     * @param oldCode 原邮箱号的验证码 （如果没有绑定过手机号可不传）
     * @return Map<String,Object>
     */
    @RequestMapping("/updateUserEmail")
    @ResponseBody
    public Map<String,Object> updateUserEmail(@RequestParam("userId") BigDecimal userId,
                                               @RequestParam("email") String email,
                                               @RequestParam("code") String code,
                                               @RequestParam(value = "oldCode",required = false) String oldCode){
        return userMobileOrEmailBindingService.bindingUserEmail(userId,email,code,oldCode);
    }


}
